var express = require('express');
var router = express.Router();
var debug = require('debug')('home');
var WeixinApi = require("../weixin/WeixinApi.js");
var weixinObj = new WeixinApi();

// get /test
router.get('/', function(req, res, next) {
	var userId = req.session.userId;

	if (!userId) {
		debug('no userId, to auth=', weixinObj.getUrlCode());
		res.redirect(weixinObj.getUrlCode());
		return;
	}

	debug('get index.html');
	res.status(200).end('thi is home, and your userId=' + userId);
	// res.redirect('/index.html');

	// save userinfo to db , TODO should use redis 
	weixinObj.getUserInfo(userId);
});


module.exports = exports = router;